using System;
using System.Collections;
using System.Collections.Generic;

namespace Genko.Model.Collections
{
	internal abstract class MutableMemberList : MemberList
	{
		private MemberList memberList = null;

		internal MutableMemberList()
		{
			this.memberList = CreateDefaultMemberList();
		}

		protected MemberList MemberList
		{
			get { return this.memberList; }
			set { this.memberList = value; }
		}

		protected abstract MemberList CreateDefaultMemberList();

		protected abstract bool MutateIfNecessary();

		public override bool IsReadOnly
		{
			get
			{
				return this.MemberList.IsReadOnly;
			}
		}

		public override Member this[int index]
		{
			get
			{
				return this.MemberList[index];
			}
			set
			{
				this.MemberList[index] = value;
			}
		}

		public override Member this[string memberId]
		{
			get
			{
				return this.MemberList[memberId];
			}
		}

		public override int IndexOf(Member item)
		{
			return this.MemberList.IndexOf(item);
		}

		public override void Insert(int index, Member item)
		{
			this.MemberList.Insert(index, item);
			MutateIfNecessary();
		}

		public override void RemoveAt(int index)
		{
			this.MemberList.RemoveAt(index);
			MutateIfNecessary();
		}

		public override void Add(Member item)
		{
			this.MemberList.Add(item);
			MutateIfNecessary();
		}

		public override void Clear()
		{
			this.memberList = CreateDefaultMemberList();
		}

		public override bool Contains(Member item)
		{
			return this.MemberList.Contains(item);
		}

		public override void CopyTo(Member[] array, int arrayIndex)
		{
			this.MemberList.CopyTo(array, arrayIndex);
		}

		public override bool Remove(Member item)
		{
			return this.MemberList.Remove(item);
		}

		public override int Count
		{
			get
			{
				return this.MemberList.Count;
			}
		}

		public override IEnumerator<Member> GetEnumerator()
		{
			return this.MemberList.GetEnumerator();
		}
	}
}
